package com.shujia.flink.core

import org.apache.flink.api.scala._
import org.apache.flink.core.fs.FileSystem.WriteMode

object Demo2batchWordCount {
  def main(args: Array[String]): Unit = {

    //创建flink  batch环境

    val env: ExecutionEnvironment = ExecutionEnvironment.getExecutionEnvironment


    ///1、读取数据
    //DataSet 相当于rdd
    val linesDS: DataSet[String] = env.readTextFile("data/words.txt")


    //将单词拆分
    val countDS: AggregateDataSet[(String, Int)] = linesDS
      .flatMap(_.split(","))
      .map((_, 1))
      .groupBy(0)
      .sum(1)


    // countDS.print()

    //保存数据
    countDS.writeAsText("data/count", WriteMode.OVERWRITE)
    //启动
    env.execute()

  }

}
